// 序列化参数,node模块提供的
import qs from 'qs';

// 统一管理项目接口地址
import request from './request.js';

// 统一管理项目接口地址出现的问题演示
// export const JingPinAPI = request.get("/products/recommend");
// export const JingPinAPI2 = request.get("/products/recommend");
// export const JingPinAPI3 = request.get("/products/recommend");
// export const JingPinAPI4 = request.get("/products/recommend");

// 此时按照上面的写法，当按需导入的时候 import {JingPinAPI} from '@/request/api.js';
// 问题：出现有多少个，就会自动发送多少个请求。
// 解决方案：按照懒加载的方式：变为函数，当调用的时候才加载。如下

// export const JingPinAPI = ()=> request.get("/products/recommend");
// export const JingPinAPI2 = ()=> request.get("/products/recommend");
// export const JingPinAPI3 = ()=> request.get("/products/recommend");
// export const JingPinAPI4 = ()=> request.get("/products/recommend");


//----------------------------------------------------------------
// export const JingPinAPI = () => request.get("/products/recommend", {
//     //请求头配置
//     headers: { 
//         token: 123456
//     }
// });

// export const JingPinAPI = () => request.get("/products/recommend", {
//      params:{
//          name:'xxx'        
//      }    
// });

// export const JingPinAPI = () => request.post("/products/recommend", {
//      name:'xxx'    
// });


//此时又有一个问题，如果每个请求到要携带token,那一直重复操作，所以要统一设置==>拦截器

// --------------------------------------------------------------------
//以上是示范问题，以下是统一管理的接口地址

// 精品推荐
export const JingPinAPI = () => request.get("/products/recommend");

// 热门兑换
export const ReMenAPI = () => request.get("/products/hot");

//手机验证码
// 接口要求：post请求的参数要进行序列化即qs.stringify(),请求传统的form表单的格式是：Content-Type:x-www-form-urlencoded
export const SendSMSAPI = params => request.post("/sendSMS", qs.stringify(params));

//测试qs.stringify()
//作用：对post请求，需要参数进行序列化即对象序列化
// console.log("qs.stringify():",qs.stringify({name:'zhangsan',age:18}));
// 经过qs.stringify()把对象转换为：name=zhangsan & age=18


// 手机号验证码登录
export const PhoneReginAPI = params => request.post("/phoneRegin", qs.stringify(params));

// 微信扫码登录
export const WeiXinLoginAPI = params => request.post("/wechatUsers/PCLogin", qs.stringify(params));

//手机绑定微信
export const WechatUsersBindingAPI = params => request.post("/wechatUsers/binding", qs.stringify(params));

//获取用户信息
export const UserInfoAPI = () => request.get("/shop/userProfiles");

//商品详情
export const GoodDetailsAPI = id=>request.get(`/products/${id}`);

//加入购物车
export const AddShopCartAPI = params =>request.post('/shop/carts/add',qs.stringify(params));

//全部商品 | 更多商品
export const ProductsAPI = params =>request.get('/products',{params});

//查询购物车
export const ShopCartsAPI = () =>request.get('/shop/carts');

//删除购物车商品
export const ShopCartsDelAPI = id => request.delete(`/shop/carts?productIds=${id}`);

//解绑微信 
export const UnBindWeChatAPI = () => request.put('/wechatUsers/unbindingWeChat');